package com.lzk.controller;

import com.lzk.domain.ResponseResult;
import com.lzk.domain.dto.AddArticleDto;
import com.lzk.domain.dto.UpdateArticleDto;
import com.lzk.domain.entity.Article;
import com.lzk.domain.entity.Menu;
import com.lzk.domain.vo.PageVo;
import com.lzk.service.ArticleService;
import com.lzk.service.MenuService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * author: 刘中魁
 */
@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private MenuService menuService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto article) {
        return articleService.add(article);
    }

    //    @GetMapping("/list")
//    public ResponseResult list(@RequestParam(value = "pageNum") Integer pageNum,
//                               @RequestParam(value = "pageSize") Integer pageSize,
//                               @RequestParam(value = "title") String title,
//                               @RequestParam(value = "summary") String summary){
//        return articleService.getArticleList(pageNum,pageSize,title,summary);
//    }
    @GetMapping("/list")
    public ResponseResult list(Article article, Integer pageNum, Integer pageSize) {
        PageVo pageVo = articleService.selectArticlePage(article, pageNum, pageSize);
        return ResponseResult.okResult(pageVo);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticleMes(@PathVariable long id){
        return articleService.getArticleMes(id);
    }

    @PutMapping
    public ResponseResult updateArticle(@RequestBody UpdateArticleDto updateArticleDto){
        return articleService.updateArticle(updateArticleDto);

    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteArticle(@PathVariable long id){
        return articleService.deleteArticle(id);
    }



}
